package com.ap.core.business.message.domain.translators.header.impl;

import com.ap.core.backoffice.dao.BackOfficeOrderPaymentDao;
import com.ap.core.backoffice.domain.BackOfficeOrderPayment;
import com.ap.core.business.message.domain.translators.AbstractHeaderTranslator;
import com.ap.core.business.message.domain.translators.BindingListener;
import com.ap.core.business.message.domain.translators.BindingMetaData;
import com.ap.core.common.types.InputMessageType;
import com.ap.core.domain.ApMessage;
import com.ap.core.exception.BusinessFailureException;
import com.ap.core.message.managerefund.info.RequestRetrieveRefundAccountInfo;

/**
 * User: Rohit.Dixit
 * Implementation class for {@link com.ap.core.business.message.domain.translators.Translator}
 */
public class RetrieveRefundAcctMsgHdrTranslator extends AbstractHeaderTranslator<RequestRetrieveRefundAccountInfo> {

	private BackOfficeOrderPaymentDao backOfficeOrderPaymentDao;
	@Override
	public void translate(RequestRetrieveRefundAccountInfo boundObject,
			BindingMetaData metaData, BindingListener bindingListener)
			throws BusinessFailureException {
		 final InputMessageType inputMessageType = metaData.getInputMessageType();
	        BackOfficeOrderPayment originalOrderPayment = null;
	        if(null != boundObject.getRefundRequestInfo().getApTransactionId()){
	            originalOrderPayment =  backOfficeOrderPaymentDao.findById(boundObject.getRefundRequestInfo().getApTransactionId());
	        }
	        final ApMessage apMessage = populateApEvent(inputMessageType, metaData.getReconciliationInfo().getReconciliationCycleId(),  metaData.getReconciliationInfo().getReconciliationDate(), boundObject.getMsgHdr().getMsgId(), boundObject.getMsgHdr().getMsgTimestamp(),  boundObject.getRefundRequestInfo().getDistributorId()) ;

	        bindingListener.onApMessageBackOffice(apMessage, originalOrderPayment);
		
	}
	public void setBackOfficeOrderPaymentDao(
			BackOfficeOrderPaymentDao backOfficeOrderPaymentDao) {
		this.backOfficeOrderPaymentDao = backOfficeOrderPaymentDao;
	}
}
